package com.biscuit.page.basicservice.persistence.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biscuit.page.basicservice.model.constant.AccountSettingConstant;
import com.biscuit.page.basicservice.model.entities.mysql.SysUserDetail;
import com.biscuit.page.basicservice.persistence.mapper.UserDetailMapper;
import com.biscuit.page.basicservice.utils.WrapperUtil;
import org.springframework.stereotype.Component;

/**
 * @author biscuit
 * @createTime 2024/6/11 10:07
 */
@Component
public class UserDetailDao extends ServiceImpl<UserDetailMapper, SysUserDetail> {

    public void initUserDetail(Long userId) {
        SysUserDetail sysUserDetail = new SysUserDetail();
        sysUserDetail.setUserId(userId);
        sysUserDetail.setBackgroundImage(AccountSettingConstant.BACKGROUND_IMAGE_DEFAULT_JSON);
        this.insertAndIncrement(sysUserDetail);
    }

    public void insertAndIncrement(SysUserDetail sysUserDetail) {
        baseMapper.insertAndIncrement(sysUserDetail);
    }

    public SysUserDetail getByUserId(Long userId) {
        LambdaQueryWrapper<SysUserDetail> queryWrapper = WrapperUtil.instanceQuery(SysUserDetail.class)
                .eq(SysUserDetail::getUserId, userId);
        return super.getOne(queryWrapper);
    }
}
